
/**
* Calculate the horizontal sum
*
* @param  String  srcPrice
* @param  String  srcQty
* @param  string  dstObject
*
*/
function calcHrzTotal(srcPrice, srcQty, dstObject){

  srcPrice = document.getElementsByName(srcPrice);
  srcPrice = srcPrice[0];
  
  srcQty = document.getElementsByName(srcQty);
  srcQty = srcQty[0];
  
  dstObject = document.getElementsByName(dstObject);
  dstObject = dstObject[0];
  
  /**
  * Just to make sure all value are valid
  *
  */
  if(!isNumeric(srcPrice.value)){
    
    
  }
  
  if(!isNumeric(srcQty.value)){
    
    
  }
  
  if(!isNumeric(dstObject.value)){
    
    
  }
  
  /**
  * Begin the calculation
  *
  */
  dstObject.value = parseFloat(srcPrice.value) * parseFloat(srcQty.value);
}

/**
* Calculate the dropBox effect
* Is to synchronized the total by current value
*
* @param  string  srcObject
* @param  integer srcRow,
* @param  string  srcQuantity
* @param  string  srcTotQuantity
* @param  string  srcCvtQuantity
* @param  string  srcTotCvtQuantity
* @param  string  srcHrzTotal
* @param  string  srcGrandTotal
*
*/
function syncOrSumVal8(srcObject,
                       srcRow,
                       srcQuantity,
                       srcTotQuantity,
                       srcCvtQuantity,
                       srcTotCvtQuantity,
                       srcHrzTotal,
                       srcGrandTotal){
  
  srcObject           = document.getElementsByName(srcObject);
  
  /**
  * Check if the object is an Array
  * YES: Make it become the 1st element by default
  * NO : Do Nothing
  *
  */
  if(srcObject.length > 0){
    
    srcObject = srcObject[srcRow];
  }
  
  srcQuantity         = document.getElementsByName(srcQuantity);
  srcTotQuantity      = document.getElementsByName(srcTotQuantity);
  
  if(srcQuantity.length > 0){
    
    srcQuantity = srcQuantity[0];
  }
  
  if(srcTotQuantity.length > 0){
    
    srcTotQuantity = srcTotQuantity[0];
  }
  
  srcCvtQuantity      = document.getElementsByName(srcCvtQuantity);
  srcTotCvtQuantity   = document.getElementsByName(srcTotCvtQuantity);
  
  if(srcCvtQuantity.length > 0){
    
    srcCvtQuantity = srcCvtQuantity[0];
  }
  
  if(srcTotCvtQuantity.length > 0){
    
    srcTotCvtQuantity = srcTotCvtQuantity[0];
  }
  
  srcHrzTotal         = document.getElementsByName(srcHrzTotal);
  srcGrandTotal       = document.getElementsByName(srcGrandTotal);
  
  if(srcHrzTotal.length > 0){
    
    srcHrzTotal = srcHrzTotal[0];
  }
  
  if(srcGrandTotal.length > 0){
    
    srcGrandTotal = srcGrandTotal[0];
  }
  
  /**
  * Check if the dropBox is checked
  * YES: Sync em
  * NO : Sum em
  *
  */
  if(srcObject.checked == true){
    
    /**
    * sync for each Object
    *
    */
    srcTotQuantity.value      = parseFloat(srcTotQuantity.value)    - parseFloat(srcQuantity.value);
    
    srcTotCvtQuantity.value   = parseFloat(srcTotCvtQuantity.value) - parseFloat(srcCvtQuantity.value);
    
    srcGrandTotal.value       = parseFloat(srcGrandTotal.value)     - parseFloat(srcHrzTotal.value);
  }else{
    
    /**
    * Sum for each Object
    *
    */
    srcTotQuantity.value      = parseFloat(srcTotQuantity.value)    + parseFloat(srcQuantity.value);
    
    srcTotCvtQuantity.value   = parseFloat(srcTotCvtQuantity.value) + parseFloat(srcCvtQuantity.value);
    
    srcGrandTotal.value       = parseFloat(srcGrandTotal.value)     + parseFloat(srcHrzTotal.value);
  }
}
